﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Imports System.Windows.Forms
Imports DevComponents.DotNetBar.Controls
Imports DevComponents.Editors.DateTimeAdv
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DTO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General

Namespace DoAnQuanLyBanHang.DAO
    Class KhachHangCtrl
        Private m_KhachHangData As New KhachHangData()

        Public Sub HienThiComboBox(cbx As ComboBox)
            Dim m_DT As DataTable = m_KhachHangData.LayKhachHang()
            cbx.DataSource = m_DT
            cbx.DisplayMember = "HoTen"
            cbx.ValueMember = "MaKH"
        End Sub

        Public Sub HienThiComboBox1(cbx As ComboBox)
            Dim m_DT As DataTable = m_KhachHangData.LayKhachHang()
            cbx.DataSource = m_DT
            cbx.DisplayMember = "DiaChi"
            cbx.ValueMember = "MaKH"
        End Sub
#Region "Hien thi ComboBox trong DataGridView"
        Public Sub HienThiDataGridViewComboBoxColumn(cmbColumn As DataGridViewComboBoxColumn)
            cmbColumn.DataSource = m_KhachHangData.LayKhachHang()
            cmbColumn.DisplayMember = "HoTen"
            cmbColumn.ValueMember = "MaKH"
            cmbColumn.DataPropertyName = "MaKH"
            cmbColumn.HeaderText = "Tên khách hàng"

        End Sub

        Public Sub LayMaTheoTen(TenKH As [String])
            Dim dt As DataTable = m_KhachHangData.LayMaKHTheoTen(TenKH)
            Me.MaKH = dt.Rows(0)("MaKH").ToString()
        End Sub

        Private m_MaKH As [String]
        Public Property MaKH() As [String]
            Get
                Return m_MaKH
            End Get
            Set(value As [String])
                m_MaKH = value
            End Set
        End Property
#End Region
#Region "hien thi"
        Public Sub HienThi(Dgv As DataGridView, bvn As BindingNavigator)
            Dim bs As New BindingSource()

            bs.DataSource = m_KhachHangData.LayKhachHang()
            bvn.BindingSource = bs
            Dgv.DataSource = bs
        End Sub

        Public Sub HienThi(dGV As DataGridViewX, bN As BindingNavigator, txtMaKH As TextBoxX, txtHoTen As TextBoxX, txtDiaChi As TextBoxX, txtSoDienThoai As TextBoxX)
            Dim bS As New BindingSource()
            bS.DataSource = m_KhachHangData.LayKhachHang()

            txtMaKH.DataBindings.Clear()
            txtMaKH.DataBindings.Add("Text", bS, "MaKH")

            txtHoTen.DataBindings.Clear()
            txtHoTen.DataBindings.Add("Text", bS, "HoTen")

            txtDiaChi.DataBindings.Clear()
            txtDiaChi.DataBindings.Add("Text", bS, "DiaChi")

            txtSoDienThoai.DataBindings.Clear()
            txtSoDienThoai.DataBindings.Add("Text", bS, "DienThoai")

            bN.BindingSource = bS
            dGV.DataSource = bS
        End Sub
#End Region
#Region "Them moi"
        Public Function ThemDongMoi() As DataRow
            Return m_KhachHangData.ThemDongMoi()
        End Function
        Public Sub ThemMoi(m_Row As DataRow)
            m_KhachHangData.ThemKhachHang(m_Row)
        End Sub
#End Region
#Region "Luu"
        Public Function LuuKhachHang() As Boolean
            Return m_KhachHangData.LuuKhachHang()
        End Function

        Public Sub LuuKhachHang(makh As [String], hoten As [String], diachi As [String], dienthoai As [String])
            m_KhachHangData.LuuKhachHang(makh, hoten, diachi, dienthoai)
        End Sub
#End Region
#Region "Tim kiem"

        Public Sub TimKiemTheoMa(m_MaKH As [String])
            m_KhachHangData.LayKHTheoMa(m_MaKH)
        End Sub

        Public Sub TimKiemTheoTen(m_HoTen As [String])
            m_KhachHangData.LayKHTheoTen(m_HoTen)
        End Sub

#End Region
    End Class
End Namespace
